package com.example.pei.ithinklearnt.adapter;

import android.net.Uri;
import android.support.v4.view.PagerAdapter;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.example.pei.ithinklearnt.view.activity.FrescoLoaderPicturesActivity;
import com.github.piasy.biv.view.BigImageView;

import java.util.List;

/**
 * Created by Pei on 2017/11/22.
 */

public class ImageShowAdapter extends PagerAdapter {

    private List<String> imageUrls;
    private AppCompatActivity mActivity;


    public ImageShowAdapter(List<String> imageUrls, AppCompatActivity activity ) {
        this.imageUrls = imageUrls;
        this.mActivity = activity;

    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        String url = imageUrls.get(position);

        BigImageView bigImageView = new BigImageView(mActivity) ;

        //bigImageView.setFailureImage("");
        bigImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mActivity.finish();
            }
        });
        bigImageView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                final FrescoLoaderPicturesActivity frescoLoaderPicturesActivity = (FrescoLoaderPicturesActivity)mActivity;
                frescoLoaderPicturesActivity.chooseDownloadPhoto();
                return false;
            }
        });
     //   bigImageView.setProgressIndicator(new ProgressPieIndicator());
        bigImageView.showImage(Uri.parse(url), Uri.parse(url));
        container.addView(bigImageView);

        return bigImageView;
    }

    @Override
    public int getCount() {
        return imageUrls != null ? imageUrls.size() : 0;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }
}
